
<script src="//res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script src="https://open.work.weixin.qq.com/wwopen/js/jwxwork-1.0.0.js"></script>
<script src="/assets/libs/jquery/dist/jquery.min.js"></script>
<div class="panel panel-default panel-intro">
    <div class="panel-heading">
        <div class="alert alert-danger-light">
            <p>正在获取客户信息中...请稍等</p>
        </div>
    </div>

</div>



<script>


    wx.config({$wx_config});
    wx.ready(function(){
        var ag_config={$ag_config};
        ag_config.success=function(res) {
            // 回调
            wx.invoke('getCurExternalContact', {
            }, function(res){
                if(res.err_msg == "getCurExternalContact:ok"){
                    userId  = res.userId ; //返回当前外部联系人userId
                    $(function(){
                        //请求参数
                        //
                        $.ajax({
                            //请求方式
                            type : "POST",
                            //请求的媒体类型
                            contentType: "application/json;charset=UTF-8",
                            //请求地址
                            url : "{:url('facrm/workweixin.index/getCustomerId')}?userid="+userId,
                            //数据，json字符串
                            //请求成功
                            success : function(result) {
                                if (result.code==1 &&result.data){
                                    window.location.href="{:url('facrm/customer.index/edit')}/ids/"+result.data+"?ref=addtabs";
                                    return;
                                }
                                alert(result.msg);
                            },
                            //请求失败，包含具体的错误信息
                            error : function(e){
                                alert('获取用户信息失败');
                            }
                        });
                    });
                }else {
                    //错误处理
                    alert('没有getCurExternalContact权限');
                }


            });
        };
        ag_config.fail=function(res) {
            if(res.errMsg.indexOf('function not exist') > -1){
                alert('版本过低请升级')
            }

        }
        wx.agentConfig(ag_config);

    });



</script>


